import axios from 'axios';
import config from "@/util/config.js";

const API_URL = config.wmUrl+'/wm/ware';

const wareAPI = {
    addWare(param, callback) {
        axios.request({
            url: `${API_URL}/add`,
            method: 'post',
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: JSON.stringify(param)
        }).then((res) => {
            callback(res.data);
        })
    },
    getWareByName(param, callback) {
        axios.get(`${API_URL}/query?wareName=${param.wareName}&page=${param.page}&limit=${param.limit}`).then((res) => {
            callback(res.data);
        })
    },
    //批量删除
    deleteMallWare(param, callback) {
        axios.request({
            url: `${API_URL}/del/mall`,
            method: 'delete',
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: JSON.stringify(param)
        }).then((res) => {
            callback(res.data);
        })
    },
    //单个删除
    deleteWare(param, callback) {
        axios.request({
            url: `${API_URL}/del?wareId=${param.wareId}&status=${param.status}`,
            method: 'delete',
        }).then((res) => {
            callback(res.data);
        })
    },
    //修改
    updateWare(param, callback) {
        axios.request({
            url: `${API_URL}/update`,
            method: 'put',
            headers: {
                "Content-Type": "application/json;charset=UTF-8"
            },
            data: JSON.stringify(param)
        }).then((res) => {
            callback(res.data);
        })
    },
    //获取库存数量
    getWareCount(param, callback) {
        axios.get(`${API_URL}/count?wareName=${param.wareName}`).then((res) => {
            callback(res.data)
        })
    }
}
export default wareAPI;